package July;

import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

public class Day0717 {
    //斐波那契数列
    public static void main(String[] args) {
        //先找最小的大于N的斐波那契数
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();

        int[] fb = new int[1000000];
        fb[0] = 0;
        fb[1] = 1;
        int i =0 ;
        for (i = 2; i < N; i++) {
            fb[i] = fb[i - 1] + fb[i - 2];
            if (fb[i] > N)
                break;
        }
        int res = Math.min(Math.abs(fb[i] - N), Math.abs(fb[i - 1] - N));
        System.out.println(res);
    }

    //合法括号序列判断
    public boolean chkParenthesis(String A, int n) {
        Stack<Character> stack = new Stack<>();
        //进行元素的处理
        if (A == null || A.length() != n)
            return false;
        //用栈进行判断
        for (int i = 0; i < A.length(); i++) {
            if (A.charAt(i) == '('){
                stack.push(A.charAt(i));
            } else if (A.charAt(i) == ')') {
                //判断是否为空
                if (stack.isEmpty())
                    return false;
                else {
                    stack.pop();
                }
            }else {
                return false;
            }
        }
        //最后再判断栈中是否为空，不为空说明它还有括号没匹配上。
        if (!stack.isEmpty())
            return false;
        else
            return true;
    }
}
